home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / Additions ƒ / StartJobMessage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-14  |  5.2 KB  |  181 lines  |  [TEXT/MPS ]

  1. /* ------------------------------------------------------------------------------
  2.  
  3.     FILENAME
  4.         StartJobMessage.c
  5.  
  6.     DESCRIPTION
  7.         This file contains the message procedure that will be invoked when the Printing Manager
  8.         issues the StartJob message.  The routine which is called is StartJobMessageProc.
  9.         Depending upon the effects the user selected in the Addition's Print dialog panel, 
  10.         StartJobMessageProc will invoke routines in the Additions.c file to produce the
  11.         desired effects.
  12.  
  13.     COPYRIGHT
  14.         Copyright Apple Computer, Inc. 1991 - 1996
  15.         All rights reserved. 
  16.     
  17.     INTERFACE ROUTINES
  18.         StartJobMessageProc
  19.  
  20.     MODIFICATION HISTORY
  21.         05/15/91            ALA        Initial Implementation
  22.          6/14/96            cn            Updated to support Universal Interfaces 2.1.
  23.  
  24.  
  25. ------------------------------------------------------------------------------- */
  26.  
  27. #include <Types.h>
  28. #include <Quickdraw.h>
  29. #include <Memory.h>
  30. #include <Resources.h>
  31. #include <Dialogs.h>
  32. #include <TextEdit.h>
  33. #include <OSUtils.h>
  34. #include <Packages.h>
  35. #include <ToolUtils.h>
  36. #include <Menus.h>
  37. #include <String.h>
  38. #include <Printing.h>
  39.  
  40. #include <GXGraphics.h>
  41. #include <GraphicsLibraries.h>
  42. #include <FontLibrary.h>
  43.  
  44. #include <Collections.h>
  45. #include <GXMessages.h>
  46.  
  47. #include    <GXPrinting.h>
  48.  
  49. #include "Utilities.h"
  50. #include "Additions.h"
  51.  
  52.  
  53. /*================================== MESSAGE INTERFACE ROUTINES ==================================*/
  54.  
  55.  
  56. /* ===== CleanupStartJobMessageProc =====
  57.  
  58.     CleanupStartJobMessageProc is the extension's routine which will be invoked when Printing issues a 
  59.     CleanupStartJob message.  If the StartJobMessageProc routine had allocated some memory, this
  60.     routine woulkd deallocate it and then call Forward_CleanupStartJob.  As it is, this
  61.     routine only calls Forward_CleanupStartJob.
  62. */
  63. void CleanupStartJobMessageProc(void)
  64. {
  65.     
  66.     /* Simply forward the cleanup message to others in the chain */
  67.     Forward_GXCleanupStartJob();
  68. }
  69. /* CleanupStartJobMessageProc */
  70.  
  71.  
  72. /* ===== StartJobMessageProc =====
  73.  
  74.     StartJobMessageProc is the extension's routine which will be invoked when Printing issues a 
  75.     StartJob message.  This routine will first make sure the job is started by calling
  76.     Forward_StartJob.  Once the job is started, it determines if a cover page should
  77.     be added to the beginning of the document.  If so, it creates a cover page and adds it
  78.     to the file by issuing the Send_SpoolPage message with the newly created page.  If no cover
  79.     page is to be added, the routine returns after calling Forward_StartJob.
  80. */
  81. OSErr StartJobMessageProc(StringPtr    docName, long pageCount)                //    (in)    name of the document
  82. {
  83.     
  84.     OSErr                         anErr;
  85.     gxShape                        coverPage;
  86.     Collection                    jobCollection;
  87.     AdditionsCollection        additionsConfig;
  88.     
  89.     gxJob printJob = GXGetJob();
  90.     
  91.     /* Get reference to the print Job's collection */
  92.     jobCollection = GXGetJobCollection(printJob);
  93.     
  94.     /* Fetch the Additions's collection we created at Print dialog time */
  95.     anErr = GetCollectionItem (jobCollection,
  96.                                         kAdditionsCollectionType,
  97.                                         gxPrintingTagID,
  98.                                         nil,
  99.                                         &additionsConfig);
  100.  
  101.  
  102.     /* if the pagecount is zero, we don't increment pageCount.  pageCount = 0  */
  103.     /* signals the spooling dialog what string to display.                            */
  104.     if ((additionsConfig.addCoverPage) && (pageCount > 0))
  105.         ++pageCount;
  106.     
  107.  
  108.     /* Make sure the job is started first */
  109.     anErr = Forward_GXStartJob(docName, pageCount);
  110.     
  111.     
  112.     if (anErr == noErr)
  113.     {
  114.         
  115.         /* Fetch the Additions's collection we created at Print dialog time */
  116.         anErr = GetCollectionItem (jobCollection,
  117.                                             kAdditionsCollectionType,
  118.                                             gxPrintingTagID,
  119.                                             nil,
  120.                                             &additionsConfig);
  121.         if (anErr == noErr)
  122.         {
  123.             /* If user selected the "cover page first" option, add the cover page to the spool file */
  124.             if ( (additionsConfig.addCoverPage) && (additionsConfig.coverPage ==    kCoverPageFirst) )
  125.             {
  126.                 gxFormat                    theFormat;
  127.                 gxJobInfo                printerInfo;
  128.     
  129.                 /* Get the format we should use for the cover page */
  130.                 theFormat = GXGetJobFormat(printJob, 1);
  131.                 
  132.                 /* Get the general printing info. collection item */
  133.                 anErr = GetCollectionItem (jobCollection,
  134.                                                     gxJobTag,
  135.                                                     gxPrintingTagID,
  136.                                                     nil,
  137.                                                     &printerInfo);
  138.                 if (anErr == noErr)
  139.                 {
  140.                     /* Create the cover page shape */
  141.                     anErr = ComposeCoverPage(&coverPage, theFormat, &printerInfo);
  142.                     if (anErr == noErr)
  143.                     {
  144.                         /* Spool the shape into the file */
  145.                         anErr = Send_GXPrintPage (theFormat, coverPage);
  146.             
  147.                         /* Dump the shape since we no longer need it */
  148.                         GXDisposeShape(coverPage);
  149.                     }
  150.                 }
  151.             }
  152.             
  153.             if (anErr == noErr)
  154.             {
  155.                 /* If we're serializing copies, save the ending serial number in the next batch */
  156.                 if (additionsConfig.serializeCopies)
  157.                 {
  158.                     /* Compute the ending serial number */
  159.                     additionsConfig.nextEndSerialNum += GetCopiesFromJob(jobCollection) - 1;
  160.                     
  161.                     /* Update the config data in the job collection */
  162.                     anErr = AddCollectionItem(    jobCollection,
  163.                                                         kAdditionsCollectionType,
  164.                                                         gxPrintingTagID,
  165.                                                         sizeof(AdditionsCollection),
  166.                                                         &additionsConfig);
  167.                 }
  168.             }
  169.             
  170.             /* If we encountered an error, force a cleanup of StartJob */
  171.             if (anErr != noErr)
  172.                 GXCleanupStartJob();
  173.         }
  174.         else    //    T => no config; don't do anything
  175.             anErr = noErr;
  176.     }
  177.     
  178.     return(anErr);
  179. }
  180. /* StartJobMessageProc */
  181.